package com.biyabi.controller;

import com.biyabi.entity.Coupon;
import com.biyabi.pojo.CouponsData;
import com.biyabi.pojo.Result;
import com.biyabi.service.CouponService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/back/coupon")
public class CouponController {
    @Resource
    private CouponService couponService;
    @RequestMapping("/findAll")
    public CouponsData findAll(Integer page, Integer rows,String columnName,String columnValue){
        return couponService.findAll(page,rows,columnName,columnValue);
    }
    @RequestMapping("/add")
    public Result add(Coupon coupon){
        Result result = new Result();
        try{
            couponService.add(coupon);
            result.setStatus(true);
            result.setMessage("添加优惠券成功！");
        }catch(Exception e){
            result.setStatus(false);
            result.setMessage("添加优惠券失败！");
        }
        return result;
    }
    @RequestMapping("/update")
    public Result update(Coupon coupon){
        Result result = new Result();
        try{
            couponService.update(coupon);
            result.setStatus(true);
            result.setMessage("更新优惠券成功！");
        }catch(Exception e){
            result.setStatus(false);
            result.setMessage("更新优惠券失败！");
        }
        return result;
    }
    @RequestMapping("/findOne")
    public Coupon findOne(String id){
        return couponService.findOne(id);
    }

}
